﻿{extend name="public:base" /}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">

                <div class="ibox-content">
                    <div class="row search-form">
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="status" class="form-control form-control-lg">
                                    <option value="0">结算状态</option>
                                    <option value="1" {:input(
                                    'status') == 1 ? 'selected' : ''}>待结算</option>
                                    <option value="2" {:input(
                                    'status') == 2 ? 'selected' : ''}>已结算</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
                                <button type="button" class="btn btn-primary btn-lg excel-btn">导出</button>
                            </div>
                        </div>
                    </div>


                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>结算周期</th>
                                <th>周期平台总业绩</th>
                                <th>门店</th>
                                <th>用户</th>
                                <th>补贴比例</th>
                                <th>门店补贴金额</th>
                                <th>结算状态</th>
                                <th>实际结算金额</th>
                                <th>结算备注</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.year}-{$vo.month}</td>
                                <td>{$vo.all_price}元</td>
                                <td>{$vo.shop_name}</td>
                                <td>{$vo.username}</td>
                                <td>{$vo.rate}%</td>
                                <td>{$vo.price}元</td>
                                <td>{$vo.status == 1 ? '待结算' : '已结算'}</td>
                                <td>{$vo.send_price}元</td>
                                <td>{$vo.remark}</td>
                                <td>
                                    {if ($vo.status == 1)}
                                    <a href="javascript:void(0)" onclick='addModelOpen({$vo.id}, {$vo.price}, "{$vo.year}-{$vo.month} 门店补贴月结")' class="btn btn-white btn-sm">
                                        <i class="fa fa-send"></i> 结算
                                    </a>
                                    {/if}
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list->items())}{$list->render()}{/if}
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!--    结算 弹出框    -->
    <div class="modal inmodal" id="myModal3" tabindex="-1" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" onclick="modelClose()"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">结算</h4>
                </div>
                <div class="modal-body">
                    <input type="text" class="form-control price" placeholder="请输入门店补贴金额">

                    <input type="text" class="form-control remark" maxlength="15" placeholder="请输入门店补贴备注" style="margin-top: 10px">

                    <input type="hidden" class="id" value="">
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-white" onclick="modelClose()">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="confirmSend()">结算</button>
                </div>
            </div>
        </div>
    </div>

</div>

{/block}

{block name="js"}
<script>
    function addModelOpen(id, price, remark) {
        $('body').addClass('modal-open').append('<div class="modal-backdrop show"></div>');
        $('#myModal3').css('display', 'block').addClass('show');

        $('.id').val(id);
        $('.price').val(price);
        $('.remark').val(remark);
    }

    /**
     * 关闭 结算 弹框
     * */
    function modelClose() {
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        $('#myModal3').css('display', 'none').removeClass('show');

        $('.id').val('');
        $('.price').val('');
        $('.remark').val('');
    }

    /**
     * 结算
     * */
    function confirmSend() {
        var id = $('.id').val();
        var price = $('.price').val();
        var remark = $('.remark').val();

        $.post("{:url('shopSubsidySend')}",{
            id: id,
            price: price,
            remark: remark
        }, function (res){
            if(res.result == 1){
                layer.msg(res.msg);
                setTimeout(function (){
                    window.location.reload();
                },500)
            }else{
                layer.msg(res.msg);
            }
        },'json')

    }
</script>
{/block}